package app.project.streetlensproject.model;

import java.io.Serializable;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import app.project.streetlensproject.HomeActivity;
import app.project.streetlensproject.util.Base64;
import app.project.streetlensproject.util.TiltDetector;

public class Place implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public float locationx;
	public float locationy;
	public String placename;	
	public String description;
	public int categoryid;
	public String uniqueid;
	public String image;
	public String created_at;
	public String updated_at;
	public float angleRotate;
	
	public boolean isFavorite = false;
	public boolean isUnapprove = false;
	private float corner = 0;

	public Place() {
		// TODO Auto-generated constructor stub
	}

	public Place(float _x, float _y, String _name,String _des, int _cate,
			String _uniqueid, String _image, String _createdDate, String _updatedDate) {
		this.locationx = _x;
		this.locationy = _y;
		this.placename = _name;		
		this.description = _des;
		this.categoryid = _cate;
		this.uniqueid = _uniqueid;
		this.image = _image;
		this.created_at = _createdDate;
		this.updated_at = _updatedDate;
	}
	
	 // params mang tinh chat tham khao
	public float updateAngleRotate(){
		// TODO: Tuan implement  
		angleRotate =  90+(GetAngle(HomeActivity.MY_LATITUDE, HomeActivity.MY_LONGITUDE, locationx, locationy)) - corner;
//		Log.d("a", ""+angleRotate);
		return angleRotate;
	}
	
	public void setCorner(float corner){
		this.corner = corner;
	}
	
	public Bitmap getBitmap(){
		try {
			byte[] imageAsBytes = Base64.decode(image.getBytes());
			return BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length);
		} catch (Exception e) {
//			e.printStackTrace();
			return null;
		}
	}
	
	
	
	/**
	 * get angle between two point in google map
	 * 
	 * @param paramDouble1
	 * @param paramDouble2
	 * @param paramDouble3
	 * @param paramDouble4
	 * @return
	 */
	public static float GetAngle(double paramDouble1, double paramDouble2,
			double paramDouble3, double paramDouble4) {
		float f = (float) (180.0F * (float) Math.atan2(paramDouble1
				- paramDouble3, Math.cos(0.01745277777777778D * paramDouble1)
				* (paramDouble2 - paramDouble4)) / 3.1415D);
		if (f >= 0.0F)
			return 180.0F - f;
		return -180.0F - f;
	}
}
